var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loadMore: false,
    page: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    wx.request({
      url: app.globalData.phpUrl + 'user/api',
      method:'POST',
      data: { api_name: 'template', openid: options.openOId, page:1, psize:5},
      success:function(e){
        wx.hideLoading();
        that.setData({
          collectData: e.data.data,
          page: that.data.page + 1
        });
      }
    })
  },
  editQuestion: function (e) {
    app.globalData.setId = e.currentTarget.dataset.id
    wx.switchTab({
      url: '../../setTopic/setTopic?source=set',
    });
  },

  onReachBottom: function () {
    var that = this;
    if (that.data.hadList == false) {
      console.log('加载完...')
      return
    }

    that.setData({
      loadMore: true
    });

    wx.request({
      url: app.globalData.phpUrl + 'user/api',
      method: 'POST',
      data: { api_name: 'template', openid: app.globalData.userData.openOId, page: that.data.page, psize: 5 },
      success: function (e) {
        wx.hideLoading();
        if (e.data.data.list.length == 0) {
          that.setData({
            hadList: false
          })
        };
        that.setData({
          'collectData.list': that.data.collectData.list.concat(e.data.data.list),
          loadMore: false,
          page: that.data.page + 1
        });
      }
    });

  }

})